package jichu;

import java.util.Queue;

public class Testpaixu {

    public static void main(String []args){
        int []aaa={34,23,13,51,11};

        maopao(aaa);
        //xuanze(aaa);
        int data= chazhao(23,aaa);
        System.out.println(data);

    }

    public static int chazhao(int a,int []aaa) {
        int min=0;
        int max=aaa.length-1;

        int mid=(min+max)/2;
        while (aaa[mid]!=a)
        {
            if (a<aaa[mid])
            {
                max=mid-1;
            }
            if (a>aaa[mid])
            {
                min=mid+1;
            }
            mid=(min+max)/2;
            if (min>max)
            {return -1;}
        }


        return  mid;
    }

    public static void maopao(int[] aaa) {
        for (int i=0;i<aaa.length-1;i++)
        {
            for (int j=0;j<aaa.length-1-i;j++)
            {
                if (aaa[j]>aaa[j+1])
                {
                    int temp=aaa[j+1];
                    aaa[j+1]=aaa[j];
                    aaa[j]=temp;
                }
            }
        }
        for (int i=0;i<aaa.length;i++)
        {
            System.out.println(aaa[i]);

        }
    }
    public static void xuanze(int[] aaa) {
        for (int i=0;i<aaa.length-1;i++)
        {
            for(int j=i+1;j<aaa.length;j++)
            {
                if (aaa[i]>aaa[j])
                {
                    int temp=aaa[j];
                    aaa[j]=aaa[i];
                    aaa[i]=temp;
                }
            }
        }

        for (int i=0;i<aaa.length;i++)
        {
            System.out.println(aaa[i]);

        }
    }


}
